#include "mandelbrot.h"
#include <iostream>
using namespace std;

bool in_mandelbrot_set (const double x, const double y,
                        int& nsteps, const int niter) {
  /**
    * TODO
    * It's easy to switch to Julia sets.
    */
  // Initial value
  Complex c(x, y);
  //0.284 - 0.0122
  //-0.0958,0.735
  //-0.181,-0.667
  //Complex c(-.181,-.667);
  // Current term
  Complex term(c.real,c.im);
  //Complex term(x,y);

  for (int k = 0; k < niter; ++k) {
    /**
      * It is proved that if the module of a term
      * of the suite is greater than 2, then the
      * suite diverges and hence the associated complex
      * doesn't belong to the Mandelbrot set.
      */
    if (term.module_square() > 4) {
      nsteps = k;
      return false;
    }
    /**
      * Calculate the next term.
      */
    term.square_add (c);
  }

  nsteps = niter - 1;
  return true;
}

